<%@ page language="java" import="java.util.*, java.text.*,com.zjut.zs.util.tools.*,com.zjut.an.util.tools.*,com.zjut.an.util.system.*,
com.zjut.zs.user.manager.*, com.zjut.zs.user.dao.*,com.zjut.zs.userstatus.manager.*, com.zjut.zs.userstatus.dao.*,
com.zjut.zs.pay.manager.*, com.zjut.zs.pay.dao.*,com.zjut.wx.pay.order.*, 
com.zjut.zs.cj.manager.*, com.zjut.zs.cj.dao.*,com.zjut.zs.xy.manager.*, com.zjut.zs.xy.dao.*,
com.zjut.zs.zxlb.manager.*, com.zjut.zs.zxlb.dao.*,com.zjut.zs.shhd.manager.*, com.zjut.zs.shhd.dao.*,
com.zjut.zs.exvalue.manager.*, com.zjut.zs.exvalue.dao.*,com.zjut.zs.coname.manager.*, 
com.zjut.zs.school.manager.*, com.zjut.zs.school.dao.*,com.zjut.zs.applyview.dao.*,com.zjut.zs.applyview.manager.*,
com.zjut.an.config.manager.*, com.zjut.an.config.dao.*" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">  
<meta name="renderer" content="webkit"> 
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/web.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../plugins/assets/plugins/jquery-3.5.1.min.js"></script>
<script src="js/qrcode.js"></script>			
</head>

<body>
<jsp:include page="zs_uservalidate.jsp" flush="true"/>
<%
if (session.getAttribute("zsUser") == null&&session.getAttribute("admin") == null) {
	out.print("<script>alert('由于长时间未操作，系统已经自动注销，请重新登陆');</script>");
	out.print("<script>top.window.location='main.jsp';</script>");
} else {
	ZsSchoolManager zsManager = (ZsSchoolManager) SpringContextUtil.getBean("ZsSchoolManager");
	ZsPayManager pmanager = (ZsPayManager) SpringContextUtil.getBean("ZsPayManager");
	ZsUserManager umanager = (ZsUserManager) SpringContextUtil.getBean("ZsUserManager");
	ZsUserStatusManager zsmanager = (ZsUserStatusManager) SpringContextUtil.getBean("ZsUserStatusManager");
	AnConfigManager anconfig = (AnConfigManager) SpringContextUtil.getBean("AnConfigManager");
	
	ZsSchool school = new ZsSchool();
	school = (ZsSchool)zsManager.getDataByInstance(1,1,null,null,school).getObjects().get(0);
	ZsUser user = (ZsUser)session.getAttribute("zsUser");
	ZsUserStatus userstatus = zsmanager.getDataByUser(user);
%>
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="index.jsp">首页</a></li>
    <li><a href="#">网上支付</a></li>
    </ul>
    </div>
    <div class="formbody">
    
	    <div class="rightinfo">
		    
			<div class="formtitle"><span>网上支付</span></div>
			<!--单页面-->  
			<div id="news1">
			        
			<br/>  
					<div class="news1content">
					<%
					if (!Status.ON.getStatus().equals(school.getScPayActive())) {
						out.println("尚未开放缴费功能。");
					} else if (!Status.CHECKSTATUS_YES.getStatus().equals(userstatus.getCheckStatus())) {
						out.println("尚未满足缴费条件");
					} else {						
						if (Status.PAYSTATUS_YES.getStatus().equals(userstatus.getPayStatus())) {
							out.println("你已经完成缴费");
						} else {
							ZsPay pay = pmanager.addData(user, Status.PAY_WX.getStatus());
							%>
							<div align="center" id="qrcode">
								<p >
								<%=pay.getPayType() %><br>
								金额：<%=anconfig.getSingleConfigInfoByName("缴费金额") %><br>
								请用微信扫描下方二维码，并完成支付
								<br>
								</p>
							</div>
							 <script>
							 	
								$(function(){
									$.get("../wxPay.action?usId=<%=user.getUsId()%>&randnum="+Math.floor(Math.random()*1000000), function(data) {
										//这个地址是Demo.java生成的code_url,这个很关键
										var url = data.codeurl;
										if (url.length==0) {
											var dom=document.createElement('DIV');
											dom.innerHTML = '二维码无法生成';
										} else {
											//参数1表示图像大小，取值范围1-10；参数2表示质量，取值范围'L','M','Q','H'
											var qr = qrcode(10, 'M');
											qr.addData(url);
											qr.make();
											var dom=document.createElement('DIV');
											dom.innerHTML = qr.createImgTag();
											var element=document.getElementById("qrcode");
											element.appendChild(dom);
										}
										
									});
									//重复执行某个方法 
    								var t1 = window.setInterval("getPayState()",5000); 
								});
								
								function getPayState(){
								    var url = '../zsApplyView.action?usId=<%=user.getUsId()%>';
								    //轮询是否已经付费
								    $.ajax({
								        type:'post',
								         url:url,
								         data:{},
								         cache:false,
								         async:true,
								         success:function(data){
								         	console.info(data);
								             if(data.rows.payStatus=='<%=Status.PAYSTATUS_YES.getStatus()%>'){
								                 window.location.reload();//刷新当前页面
								             }
								         }
								     });
								}								
							 </script>
							
							<%							
						}	
					}
					 %>
					 <div style="margin:0 auto;"><%out.print(anconfig.getSingleConfigInfoByName("缴费需知")); %></div>
					</div>
			</div>
	    </div>
    </div>
<%} %>
</body>

</html>
